package fudan.se.project.repository.projection;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import fudan.se.project.domain.conference.post.Rebuttal;
import fudan.se.project.domain.conference.production.ReviewInfo;
import fudan.se.project.repository.projection.summary.RoleSummary;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ReviewInfoProjection implements IReview {

    private final ReviewInfo reviewInfo;
    protected Rebuttal rebuttal;



    public ReviewInfoProjection(ReviewInfo reviewInfo) {
        this.reviewInfo = reviewInfo;
    }

    public ReviewInfoProjection(ReviewInfo reviewInfo, Rebuttal rebuttal) {
        this.reviewInfo = reviewInfo;
        this.rebuttal = rebuttal;
    }

    @Override
    public Long getId() {
        return this.reviewInfo.getId();
    }

    @Override
    public RoleSummary getPcMember() {
        return new RoleSummary(this.reviewInfo.getPcMember());
    }

    @Override
    @JsonIgnoreProperties("reviewInfos")
    public PaperProjection getPaper() {
        if (null == rebuttal) {
            return PaperProjection.project(this.reviewInfo.getPaper());
        } else {
            return PaperProjection.project(this.rebuttal);
        }
    }


    @Override
    public int getReviewInfoState() {
        ReviewInfo.ReviewInfoState state = this.reviewInfo.getReviewInfoState();
        return state == null ? -1 : state.ordinal();
    }

    @Override
    public String getComment() {
        return this.reviewInfo.getComment();
    }

    @Override
    public int getReviewConfidence() {
        ReviewInfo.ReviewConfidence confidence = this.reviewInfo.getReviewConfidence();
        return confidence == null ? -1 : confidence.ordinal();
    }


    @Override
    public boolean getIsCompleted() {
        return this.reviewInfo.isCompleted();
    }

    @Override
    public int getVersion() {
        return this.reviewInfo.getVersion();
    }

    public static ReviewInfoProjection project(ReviewInfo reviewInfo) {
        return new ReviewInfoProjection(reviewInfo);
    }

    public static ReviewInfoProjection project(ReviewInfo reviewInfo, Rebuttal rebuttal) {
        return new ReviewInfoProjection(reviewInfo, rebuttal);
    }

    public static List<ReviewInfoProjection> project(Collection<ReviewInfo> values) {
        ArrayList<ReviewInfoProjection> arrayList = new ArrayList<>(values.size());
        for (ReviewInfo value : values) {
            arrayList.add(project(value));
        }
        return arrayList;
    }

}
